package com.wanggsx.library.util;

import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wanggsx.library.base.views.MyRefreshAnimFooter;
import com.wanggsx.library.base.views.MyRefreshAnimHeader;

public class UtilsAnim {
    /**
     * 设置刷新动画
     * */
    public static void setRefreshAnimation(Context context, RefreshLayout refreshLayout, OnRefreshListener onRefreshListener, boolean isNowRefresh){
        refreshLayout.setRefreshHeader(new MyRefreshAnimHeader(context));
        refreshLayout.setEnableRefresh(true);
        refreshLayout.setOnRefreshListener(onRefreshListener);
        if (isNowRefresh){
            toRefreshAnim(refreshLayout);
        }
    }
    /**
     * 开启一次刷新动画
     * */
    public static void toRefreshAnim(RefreshLayout refreshLayout){
        refreshLayout.autoRefresh();
        refreshLayout.finishRefresh(1050);
    }
    /**
     * 设置加载更多动画
     * */
    public static void setLoadMoreAnimation(Context context, RefreshLayout refreshLayout, OnLoadMoreListener onLoadMoreListener, boolean isNowLoadMore){
        refreshLayout.setRefreshFooter(new MyRefreshAnimFooter(context));
        refreshLayout.setEnableLoadMore(true);
        refreshLayout.setOnLoadMoreListener(onLoadMoreListener);
        if (isNowLoadMore){
            toLoadMoreAnim(refreshLayout);
        }
    }
    /**
     * 开启一次加载更多动画
     * */
    public static void toLoadMoreAnim(RefreshLayout refreshLayout){
        refreshLayout.autoLoadMore();
        refreshLayout.finishLoadMore(1050);
    }

    /**
     * 设置刷新动画
     * */
    public static void setRefreshAnimationForBaseQuickAdapter(Context context, BaseQuickAdapter adapter, OnRefreshListener onRefreshListener, boolean isNowRefresh){
        adapter.setUpFetchEnable(true);
        adapter.setUpFetchListener(new BaseQuickAdapter.UpFetchListener() {
            @Override
            public void onUpFetch() {

            }
        });
    }

}
